#include<stdio.h>
#include<string.h>
#include<assert.h>

void* my_memmove(void* p,const void* pa, size_t num)
{
	assert(p && pa);
	char* str1 = (char*)p;
	char* str2 = (char*)pa;
	if (p < pa)
	{
		while (num--)
		{
			*str1 = *str2;
			str1++;
			str2++;
		}
	}
		if (p >pa)
		{
			str1 += num;
			str2 += num;
			while (num--)
			{
				*str1 = *str2;
				str1--;
				str2--;
			}
		}
		else
			return p;
	return p;

}

/**void* my_memmove(void* p, const void* pa, size_t num)
{
	assert(p && pa);
	char* str1 = (char*)p;
	char* str2 = (char*)pa;
	while (num--)
	{
		if (p < pa)
		{
			*str1 = *str2;
			str1++;
			str2++;
		}
		else if (p > pa)
		{

			*(str1+ num -1) = *(str2 + num-1 );
		}
		else if (p ==pa)
			return p;
	}
	return p;
}/**/
int main()
{
	int i = 0;
	int arr[] = { 1,2,3,4,5,6,7,8,9 };
	int arr1[20] = { 0 };
	my_memmove(arr+2, arr+4, 5 * sizeof(int));
	for (i = 0;i <= 7;i++)
	{
		printf("%d  ", arr[i]);
	}
	return 0;
}